package com.sheng.center.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.sheng.center.entity.Plan;
import com.sheng.center.entity.Staff;
import com.sheng.center.entity.Student;
import com.sheng.center.service.PlanService;
import com.sheng.center.service.StaffService;
import com.sheng.center.service.StudentService;
import com.sheng.center.util.Pager;

public class StaffAction extends ActionSupport implements ModelDriven<Staff>{
	/**
	 * 
	 */
	private static final long serialVersionUID = 5100172268345655217L;
	protected String forwardView;
	protected static final String STUDENT_Examine_JSP = "/WEB-INF/page/Student_examine.jsp";
	protected static final String EDIT_JSP = "/WEB-INF/page/Staff_edit.jsp";//审核报名
	protected static final String LIST_JSP = "/WEB-INF/page/Staff_list.jsp";//查询全部的报名信息
    private Staff staff = new Staff();
    private Student student = new Student();
    private List<Staff> list;
    private Pager<Staff> page;
    private String number;
	private Integer pageNo;
	private StaffService staffService;
	private PlanService planService;
	private StudentService studentService;
	
	
	private String LoginUser;
	private String aaa;
	private String bbb;
	private String ccc;
	@Override
	public Staff getModel() {
		return staff;
	}
	
	
	/**
	 * 
	 * @Title: openAdd、openEdit
	 * @Description: 拦截动作打开对应页面
	 * @param @return 参数
	 * @return String 返回类型
	 * @author huangshengjun 1532950421@qq.com
	 * @date 2019年12月10日 下午8:36:29 
	 * @throws
	 */
	public String openAdd(){
		setForwardView(STUDENT_Examine_JSP);
		return SUCCESS;
	}
	
	/**
	 * 
	 * @Title: openEdit
	 * @Description: 打开审核学生报名
	 * @param @return 参数
	 * @return String 返回类型
	 * @author huangshengjun 1532950421@qq.com
	 * @date 2019年12月21日 下午8:46:19 
	 * @throws
	 */
	public String openEdit() {
		HttpServletRequest request = ServletActionContext.getRequest();
		list = staffService.findAllList(staff);
		number = request.getParameter("pageNumber");//计算前后页码
		if(number != null&&!number.equals("")) {
			pageNo = Integer.parseInt(number);
		}
		pageNo=(pageNo==null?1:pageNo);
		page = new Pager<Staff>(5,pageNo,list);//每页多少数据，
		System.out.println("分页后的lsit"+page.getList().size());
		request.setAttribute("result", page);
		setForwardView(EDIT_JSP);
		return SUCCESS;
	}
	/**
	 * 
	 * @Title: verify
	 * @Description: 异步检测是否报名了
	 * @param @return 参数
	 * @return String 返回类型
	 * @author huangshengjun 1532950421@qq.com
	 * @date 2019年12月21日 下午11:14:12 
	 * @throws
	 */
	public String verify() {
		return staffService.verify(staff);
	}
	
	/**
	 * 
	 * @Title: 
	 * @Description: list列表，add添加，edit修改，delete删除
	 * @param @return 参数
	 * @return String 返回类型
	 * @author huangshengjun 1532950421@qq.com
	 * @date 2019年12月10日 下午8:37:20 
	 * @throws
	 */
	public String list() {
		HttpServletRequest request = ServletActionContext.getRequest();
		list = staffService.findAllList(staff);
		number = request.getParameter("pageNumber");//计算前后页码
		if(number != null&&!number.equals("")) {
			pageNo = Integer.parseInt(number);
		}
		pageNo=(pageNo==null?1:pageNo);
		page = new Pager<Staff>(5,pageNo,list);//每页多少数据，
		System.out.println("分页后的lsit"+page.getList().size());
		request.setAttribute("result", page);
		setForwardView(LIST_JSP);
		return SUCCESS;
	}
	
	public String add() {
		student.setUsername(LoginUser);
		student = studentService.findByUsername(student);
		System.out.println("===添加的用户"+LoginUser+";"+student.getSaveAddress());
		staff.setPlanId(aaa);
		staff.setPlanName(bbb);
		staff.setRequirement(ccc);
		staff.setUsername(student.getUsername());
		staff.setStudentId(student.getStudentId());
		staff.setSaveAddress(student.getSaveAddress());
		staff.setIsAgree(0);
		staffService.add(staff);
		setForwardView(STUDENT_Examine_JSP);
		return SUCCESS;
	}
	
	/**
	 * 
	 * @Title: delete
	 * @Description: 根据id查询这条信息并赋值，然后在daoImpl进行删除操作
	 * @param @return 参数
	 * @return String 返回类型
	 * @author huangshengjun 1532950421@qq.com
	 * @date 2019年12月11日 下午5:14:45 
	 * @throws
	 */
	public String delete() {
		staff = staffService.findById(staff);
		staffService.delete(staff);
		return list();
	}

	/**
	 * 
	 * @Title: One
	 * @Description:学生报名后审核同意通过
	 * @param @return 参数
	 * @return String 返回类型
	 * @author huangshengjun 1532950421@qq.com
	 * @date 2019年12月21日 下午8:59:49 
	 * @throws
	 */
	public String One() {
		staff = staffService.findById(staff);
		staff.setIsAgree(1);
		staffService.edit(staff);
		return list();
	}
	/**
	 * 
	 * @Title: Two
	 * @Description: 学生报名后审核不同意通过
	 * @param @return 参数
	 * @return String 返回类型
	 * @author huangshengjun 1532950421@qq.com
	 * @date 2019年12月21日 下午8:59:54 
	 * @throws
	 */
	public String Two() {
		staff = staffService.findById(staff);
		staff.setIsAgree(2);
		staffService.edit(staff);
		return list();
	}

	public String getForwardView() {
		return forwardView;
	}


	public void setForwardView(String forwardView) {
		this.forwardView = forwardView;
	}


	public Staff getStaff() {
		return staff;
	}


	public void setStaff(Staff staff) {
		this.staff = staff;
	}


	public List<Staff> getList() {
		return list;
	}


	public void setList(List<Staff> list) {
		this.list = list;
	}


	public Pager<Staff> getPage() {
		return page;
	}


	public void setPage(Pager<Staff> page) {
		this.page = page;
	}


	public String getNumber() {
		return number;
	}


	public void setNumber(String number) {
		this.number = number;
	}


	public Integer getPageNo() {
		return pageNo;
	}


	public void setPageNo(Integer pageNo) {
		this.pageNo = pageNo;
	}


	public StaffService getStaffService() {
		return staffService;
	}


	public void setStaffService(StaffService staffService) {
		this.staffService = staffService;
	}


	public StudentService getStudentService() {
		return studentService;
	}


	public void setStudentService(StudentService studentService) {
		this.studentService = studentService;
	}


	public String getLoginUser() {
		return LoginUser;
	}


	public String getAaa() {
		return aaa;
	}


	public void setAaa(String aaa) {
		this.aaa = aaa;
	}


	public Student getStudent() {
		return student;
	}


	public void setStudent(Student student) {
		this.student = student;
	}


	public void setLoginUser(String loginUser) {
		LoginUser = loginUser;
	}





	public String getBbb() {
		return bbb;
	}


	public void setBbb(String bbb) {
		this.bbb = bbb;
	}


	public String getCcc() {
		return ccc;
	}


	public void setCcc(String ccc) {
		this.ccc = ccc;
	}


	public PlanService getPlanService() {
		return planService;
	}


	public void setPlanService(PlanService planService) {
		this.planService = planService;
	}
	
	
}
